{# SPDX-License-Identifier: Apache-2.0 -#}

{% extends "admin/base.html" %}

{% import "admin/utils/pagination.html" as pagination %}

{% block title %}Organizations{% endblock %}

{% block breadcrumb %}
  <li class="breadcrumb-item active">Organizations</li>
{% endblock %}

{% block content %}
<div class="card">
  <div class="card-body">
    <form>
      <div class="input-group input-group-lg">
        <input id="q" name="q" type="text" class="form-control input-lg" placeholder="Search"{% if query %} value="{{ query }}"{% endif %} aria-describedby="qHelpBlock">
        <div class="input-group-btn input-group-append">
          <button type="submit" class="btn btn-default"><i class="fa fa-search"></i></button>
        </div>
      </div>
      <div id="qHelpBlock" class="help-block no-margin">
        Examples: word "whole phrase"
        <a href="#" data-input="q" data-append="name:">name:</a>psf
        <a href="#" data-input="q" data-append="organization:">org:</a>python
        <a href="#" data-input="q" data-append="url:">url:</a>.org
        <a href="#" data-input="q" data-append="description:">desc:</a>"open source"
        <br>
        Filters:&nbsp;
        <div class="btn-group btn-group-sm" role="group" data-input="q" data-state="status" aria-label="Status">
          <button type="button" class="btn btn-secondary {{ 'active' if 'is:active' in terms else '' }}" data-status="is:active">Active</button>
          <button type="button" class="btn btn-secondary {{ 'active' if 'is:inactive' in terms else '' }}" data-status="is:inactive">Inactive</button>
        </div>&nbsp;
        <div class="btn-group btn-group-sm" role="group" data-input="q" data-state="status" aria-label="Type">
          <button type="button" class="btn btn-secondary {{ 'active' if 'type:company' in terms else '' }}" data-status="type:company">Company</button>
          <button type="button" class="btn btn-secondary {{ 'active' if 'type:community' in terms else '' }}" data-status="type:community">Community</button>
        </div>
      </div>
    </form>
  </div>
</div>

<div class="card">
  <div class="card-body table-responsive p-0">
    <table class="table table-hover">
      <thead>
      <tr>
        <th>Account Name</th>
        <th>Organization</th>
        <th>Description</th>
        <th>Type</th>
        <th>Status</th>
        <th>Subscription</th>
        <th>Good Standing</th>
      </tr>
      </thead>

      <tbody>
      {% for organization in organizations %}
      <tr>
        <td>
          <a href="{{ request.route_path('admin.organization.detail', organization_id=organization.id) }}">{{ organization.name }}</a>
        </td>
        <td>
          <a href="{{ organization.link_url }}" rel="nofollow noopener noreferrer" target="_blank">{{ organization.display_name }} <i class="fa-solid fa-arrow-up-right-from-square"></i></a>
        </td>
        <td>{{ organization.description }}</td>
        <td>{{ organization.orgtype.value }}</td>
        {% if organization.is_active %}
        <td><i class="fa fa-fw fa-check text-green"></i> Active</td>
        {% else %}
        <td><i class="fa fa-fw fa-times text-red"></i> Inactive</td>
        {% endif %}
        {% if organization.good_standing %}
        <td><i class="fa fa-fw fa-check text-green"></i> Yes</td>
        {% else %}
        <td><i class="fa fa-fw fa-times text-red"></i> No</td>
        {% endif %}
      </tr>
      {% endfor %}
      </tbody>
    </table>
  </div>

  <div class="card-footer">
    <div class="row">
      <div class="col-sm-5">
        {{ pagination.summary(organizations) }}
      </div>

      <div class="col-sm-7">
        <div class="float-right">
          {{ pagination.paginate(organizations) }}
        </div>
      </div>
    </div>
  </div>
</div>
{% endblock content %}
